home *** CD-ROM | disk | FTP | other *** search
- /* Open and close files for bison,
- copyright (C) 1984 Bob Corbett and Richard Stallman
-
- Permission is granted to anyone to make or distribute verbatim copies of this program
- provided that the copyright notice and this permission notice are preserved;
- and provided that the recipient is not asked to waive or limit his right to
- redistribute copies as permitted by this permission notice;
- and provided that anyone possessing an executable copy
- is granted access to copy the source code, in machine-readable form,
- in some reasonable manner.
-
- Permission is granted to distribute derived works or enhanced versions of
- this program under the above conditions with the additional condition
- that the entire derivative or enhanced work
- must be covered by a permission notice identical to this one.
-
- Anything distributed as part of a package containing portions derived
- from this program, which cannot in current practice perform its function usefully
- in the absense of what was derived directly from this program,
- is to be considered as forming, together with the latter,
- a single work derived from this program,
- which must be entirely covered by a permission notice identical to this one
- in order for distribution of the package to be permitted.
-
- In other words, you are welcome to use, share and improve this program.
- You are forbidden to forbid anyone else to use, share and improve
- what you give them. Help stamp out software-hoarding! */
-
- #include <stdio.h>
- #ifdef unix
- #include <sys/param.h>
- #endif
- #include "files.h"
- #include "new.h"
- #include "gram.h"
-
- FILE *finput = NULL;
- FILE *foutput = NULL;
- FILE *fdefines = NULL;
- FILE *ftable = NULL;
- FILE *fattrs = NULL;
- FILE *fguard = NULL;
- FILE *faction = NULL;
- FILE *fparser = NULL;
- FILE *fparser1 = NULL;
-
- char *infile;
- char *outfile;
- char *defsfile;
- char *tabfile;
- char *attrsfile;
- char *guardfile;
- char *actfile;
- char *pfile;
- char *pfile1;
-
- extern int verboseflag;
- extern int definesflag;
- int fixed_outfiles = 0;
-
-
- char*
- stringappend(string1, end1, string2)
- char *string1;
- int end1;
- char *string2;
- {
- register char *ostring;
- register char *cp, *cp1;
- register int i;
-
- cp = string2; i = 0;
- while (*cp++) i++;
-
- ostring = NEW2(i+end1+1, char);
-
- cp = ostring;
- cp1 = string1;
- for (i = 0; i < end1; i++)
- *cp++ = *cp1++;
-
- cp1 = string2;
- while (*cp++ = *cp1++) ;
-
- return ostring;
- }
-
-
-
- openfiles()
- {
- static char *openerror = "cannot open %s";
-
- pfile = PFILE;
- pfile1 = PFILE1;
-
- {
- char *name_base;
- register int i;
- register char *cp;
-
- name_base = fixed_outfiles ? "y.y" : infile;
-
- cp = name_base;
- i = 0;
- while (*cp++) i++;
-
- cp -= 2;
-
- if (*cp-- == 'y' && *cp == '.')
- i -= 2;
-
- outfile = stringappend(name_base, i, ".output");
- defsfile = stringappend(name_base, i, ".tab.h");
- tabfile = stringappend(name_base, i, ".tab.c");
- attrsfile = stringappend(name_base, i, ".stype.h");
- guardfile = stringappend(name_base, i, ".guard.c");
- actfile = stringappend(name_base, i, ".action.c");
- }
-
- finput = fopen(infile, "r");
- if (finput == NULL)
- fatals(openerror, infile);
-
- fparser = fopen(pfile, "r");
- if (fparser == NULL)
- fatals(openerror, pfile);
-
- fparser1 = fopen(pfile1, "r");
- if (fparser1 == NULL)
- fatals(openerror, pfile1);
-
- if (verboseflag)
- {
- foutput = fopen(outfile, "w");
- if (foutput == NULL)
- fatals(openerror, outfile);
- }
-
- if (definesflag)
- {
- fdefines = fopen(defsfile, "w");
- if (fdefines == NULL)
- fatals(openerror, defsfile);
- }
-
- faction = fopen(actfile, "w");
- if (faction == NULL)
- fatals(openerror, actfile);
-
- ftable = fopen(tabfile, "w");
- if (ftable == NULL)
- fatals(openerror, tabfile);
-
- }
-
-
-
- /* open the output files needed only for the semantic parser.
- This is done when %semantic_parser is seen in the declarations section. */
- open_extra_files()
- {
- static char *openerror = "cannot open %s";
-
- fattrs = fopen(attrsfile, "w");
- if (fattrs == NULL)
- fatals(openerror, attrsfile);
-
- fguard = fopen(guardfile, "w");
- if (fguard == NULL)
- fatals(openerror, guardfile);
-
- }
-
-
-
- done(k)
- int k;
- {
- if (faction)
- fclose(faction);
-
- if (fattrs)
- fclose(fattrs);
-
- if (fguard)
- fclose(fguard);
-
- if (finput)
- fclose(finput);
-
- if (fparser)
- fclose(fparser);
-
- if (fparser1)
- fclose(fparser1);
-
- if (ftable)
- fclose(ftable);
-
- if (foutput)
- fclose(foutput);
-
- exit(k);
- }
-